package com.ipc.app.dal.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ipc.app.dal.dao.CarDAO;
import com.ipc.app.dal.doObject.CarDO;

/**
 * @author haijie.zhang
 * 
 */
public class CarDAOImpl extends HibernateDaoSupport implements CarDAO {

	public void createDAO(CarDO carDO) {
		this.getHibernateTemplate().saveOrUpdate(carDO);
	}

	@SuppressWarnings("unchecked")
	public List<CarDO> getCarDOByUserID(String userId) {

		List<CarDO> carDOs = this.getHibernateTemplate().findByNamedQuery(
				"queryCarListByUserId", userId);
		return carDOs;
	}

	public CarDO getCarDOByID(String carID) {
		CarDO carDO = (CarDO) this.getHibernateTemplate().get(CarDO.class,
				carID);
		return carDO;
	}

	@SuppressWarnings("unchecked")
	public CarDO getCarDOByCarLicense(String carLicense) {
		List<CarDO> carDOs = this.getHibernateTemplate().findByNamedQuery(
				"queryCarListByCarLicense", carLicense);
		if (null != carDOs && carDOs.size() > 0) {
			return carDOs.get(0);
		}
		return null;
	}
}
